package com.itheima.dubbo.mongodb.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.commons.pojo.mongo.Peach;
import com.itheima.dubbo.interfaces.PeachBlossomApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import java.util.List;

@Service
public class PeachBlossomImpl implements PeachBlossomApi
{
    @Autowired
    private MongoTemplate mongoTemplate;
    @Override
    public void addPeach(Peach peach) {
        mongoTemplate.save(peach);
    }


    @Override
    public Peach findUserById(Long userId) {
        return mongoTemplate.findOne(Query.query(Criteria.where("userId").is(userId)),Peach.class);
    }

    @Override
    public List<Peach> findAllUrlIsNotMine(Long userId) {
     return    mongoTemplate.find(Query.query(Criteria.where("userId").nin(userId)),Peach.class);
    }

}
